const path = require('path')
function resolve (dir) {
  return path.join(__dirname,dir)
}

const port = process.env.port || process.env.npm_config_port || 81 // 端口

module.exports = ({
  transpileDependencies: true,
  configureWebpack: {
    resolve: {
      fallback: {
        path: require.resolve('path-browserify'),
      },
    },
  },
  devServer: {
    open: true,
    host: '0.0.0.0',
    port: port,
    proxy: {
      [process.env.VUE_APP_BASE_URL]: {
        target: 'http://127.0.0.1:8181',
        changeOrigin: true,
        pathRewrite: {
          ['^' + process.env.VUE_APP_BASE_URL]: ''
        }
      }
    },
    client: {
      overlay: false
    }
  },
  chainWebpack(config) {
// set svg-sprite-loader
    config.module
      .rule('svg')
      .exclude.add(resolve('src/assets/icons'))
      .end()
    config.module
      .rule('icons')
      .test(/\.svg$/)
      .include.add(resolve('src/assets/icons'))
      .end()
      .use('svg-sprite-loader')
      .loader('svg-sprite-loader')
      .options({
        symbolId: 'icon-[name]'
      })
      .end()
  }
})
